package cn.wizzer.app.web.modules.controllers.open;

import cn.wizzer.app.sys.modules.models.SysApk;
import cn.wizzer.app.sys.modules.services.SysApkService;
import cn.wizzer.framework.util.Result;
import cn.wizzer.framework.util.param.ParamVerify;
import com.alibaba.dubbo.config.annotation.Reference;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;

import java.util.List;

@IocBean
@At("/open/app")
public class ApiApkController {
    @Inject
    @Reference
    private SysApkService apkService;

    @At
    @Ok("json")
    public Result newest(@ParamVerify(required = true) String type) {
        List<SysApk> query = apkService.query(
                Cnd.where("type", "=", type)
                        .and("delFlag","=","0")
                        .limit(0, 1)
                        .orderBy("ctAt", "desc"));
        return Result.success().addData(query.size() > 0 ? query.get(0) : null);
    }
}
